﻿using System.Web.Script.Serialization;
using DevExpress.Web.ASPxCallback;
using DevExpress.Web.ASPxEditors;
using Kaysite.Controller;
using Kaysite.Manager;
using Kaysite.Model;

public partial class Controls_AdminControls_OfficeLocationEdit : BaseEditControl<OfficeManager, OfficeController, Office>
{
    protected override string ValidationGroupName
    {
        get { return string.Empty; }
    }

    protected override string BackUrl
    {
        get
        {
            return string.Format("{0}?view=OfficeList", Request.Path);
        }
    }

    protected override ASPxCallback GetCallbackControl()
    {
        return clbkSave;
    }

    protected override ASPxButton GetCancelButton()
    {
        return btnCancel;
    }

    protected override ASPxButton GetOkButton()
    {
        return btnOk;
    }

    protected override void InitControlsByModelData(Office model)
    {
        if (model==null)
            return;
        ShowTitle(model.OfficeName);
        lblCity.Text = model.City;
        lblAddress1.Text = model.Address;
        lblAddress2.Text = model.Address2;
        lblPhone1.Text = model.Phone1;
        lblPhone2.Text = model.Phone2;
        lblPhone3.Text = model.Phone3;
        hfValues.Value = new JavaScriptSerializer().Serialize(model.GetMarker());
    }

    protected override void LoadModelDataFromControls(Office model)
    {
        var serializer = new JavaScriptSerializer();
        var marker = serializer.Deserialize<OfficeMarker>(hfValues.Value);
        model.Lat = marker.Lat;
        model.Lng = marker.Lng;
    }
}